package com.symaster.common.geom.show.node.element.menu;

import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.intellij.uiDesigner.core.Spacer;
import com.symaster.common.geom.show.node.api.LeftMenu;
import com.symaster.common.geom.show.node.api.listener.SelectChangeListener;
import com.symaster.common.geom.show.node.api.listener.UnitChangeListener;
import com.symaster.common.geom.show.node.event.SelectEvent;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ItemEvent;
import java.util.Collections;
import java.util.List;

/**
 * @author yinmiao
 * @version 2023/7/4
 */
public class CoordinateTransformation extends LeftMenu implements UnitChangeListener, SelectChangeListener {

    private JPanel root_panel;
    private JButton auto_move_button;
    private JButton re_layout_button;
    private JCheckBox enable_cavity_check_box;
    private JCheckBox reset_point_check_box;
    private JButton auto_layout_button;
    private JButton auto_layout_config_button;
    private JTextField x_input;
    private JTextField y_input;
    private JTextField angle_input;
    private JLabel x_unit_label;
    private JLabel y_unit_label;

    public CoordinateTransformation() {
    }

    @Override
    public String title() {
        return "坐标变换";
    }

    @Override
    public JComponent body() {
        return root_panel;
    }

    @Override
    public List<UnitChangeListener> unitChangeListener() {
        return Collections.singletonList(this);
    }

    @Override
    public List<SelectChangeListener> selectChangeListener() {
        return Collections.singletonList(this);
    }

    @Override
    public void unitChangeListener(ItemEvent event) {
        if (ItemEvent.SELECTED == event.getStateChange()) {
            Object item = event.getItem();
            SwingUtilities.invokeLater(() -> {
                x_unit_label.setText("  " + item);
                y_unit_label.setText("  " + item);
            });
        }
    }

    @Override
    public void select(List<SelectEvent> evn) {

    }

    {
// GUI initializer generated by IntelliJ IDEA GUI Designer
// >>> IMPORTANT!! <<<
// DO NOT EDIT OR ADD ANY CODE HERE!
        $$$setupUI$$$();
    }

    /**
     * Method generated by IntelliJ IDEA GUI Designer
     * >>> IMPORTANT!! <<<
     * DO NOT edit this method OR call it in your code!
     *
     * @noinspection ALL
     */
    private void $$$setupUI$$$() {
        root_panel = new JPanel();
        root_panel.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
        final JPanel panel1 = new JPanel();
        panel1.setLayout(new GridLayoutManager(3, 1, new Insets(0, 0, 0, 0), -1, -1));
        root_panel.add(panel1, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        auto_move_button = new JButton();
        auto_move_button.setEnabled(false);
        auto_move_button.setText("自动对齐");
        panel1.add(auto_move_button, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        re_layout_button = new JButton();
        re_layout_button.setEnabled(false);
        re_layout_button.setText("重新排列");
        panel1.add(re_layout_button, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
        final JToolBar toolBar1 = new JToolBar();
        panel1.add(toolBar1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 20), null, 0, false));
        auto_layout_button = new JButton();
        auto_layout_button.setLabel("自动排列");
        auto_layout_button.setText("自动布局");
        toolBar1.add(auto_layout_button);
        enable_cavity_check_box = new JCheckBox();
        enable_cavity_check_box.setText("包括空腔");
        toolBar1.add(enable_cavity_check_box);
        reset_point_check_box = new JCheckBox();
        reset_point_check_box.setText("坐标重置");
        toolBar1.add(reset_point_check_box);
        auto_layout_config_button = new JButton();
        auto_layout_config_button.setText("");
        toolBar1.add(auto_layout_config_button);
        final Spacer spacer1 = new Spacer();
        root_panel.add(spacer1, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_VERTICAL, 1, GridConstraints.SIZEPOLICY_WANT_GROW, null, null, null, 0, false));
        final JPanel panel2 = new JPanel();
        panel2.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1));
        root_panel.add(panel2, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JPanel panel3 = new JPanel();
        panel3.setLayout(new GridLayoutManager(4, 1, new Insets(0, 0, 0, 0), -1, -1));
        panel2.add(panel3, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
        final JToolBar toolBar2 = new JToolBar();
        panel3.add(toolBar2, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 20), null, 0, false));
        final JLabel label1 = new JLabel();
        label1.setText(" X   ");
        toolBar2.add(label1);
        x_input = new JTextField();
        x_input.setEditable(true);
        x_input.setEnabled(false);
        toolBar2.add(x_input);
        x_unit_label = new JLabel();
        x_unit_label.setText("");
        toolBar2.add(x_unit_label);
        final JToolBar toolBar3 = new JToolBar();
        panel3.add(toolBar3, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 20), null, 0, false));
        final JLabel label2 = new JLabel();
        label2.setText(" Y   ");
        toolBar3.add(label2);
        y_input = new JTextField();
        y_input.setEditable(true);
        y_input.setEnabled(false);
        toolBar3.add(y_input);
        y_unit_label = new JLabel();
        y_unit_label.setText("");
        toolBar3.add(y_unit_label);
        final JToolBar toolBar4 = new JToolBar();
        panel3.add(toolBar4, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(-1, 20), null, 0, false));
        final JLabel label3 = new JLabel();
        label3.setText("角度 ");
        toolBar4.add(label3);
        angle_input = new JTextField();
        angle_input.setEnabled(false);
        toolBar4.add(angle_input);
    }

    /**
     * @noinspection ALL
     */
    public JComponent $$$getRootComponent$$$() {
        return root_panel;
    }
}
